﻿using System;
using Microsoft.Xna.Framework;
using WindowsGame.Data;
using WindowsGame.Enums;
using WindowsGame.GameObjects;
using WindowsGame.Library;

namespace WindowsGame.Manager
{
	/// <summary>
	/// GameObjectManager is responsible for managing all objects in game.
	/// </summary>
	public interface IGameObjectManager
	{
		void LoadData(AllData data);
		void Reset();
		void Update(GameTime gameTime);
		void Draw();
	}

	public class GameObjectManager : IGameObjectManager
	{
		private readonly ISpriteManager spriteManager;

		private GameSize gameSize;
		private GameBoard gameBoard;

		public GameObjectManager(ISpriteManager spriteManager)
		{
			this.spriteManager = spriteManager;
		}

		public void LoadData(AllData data)
		{
			Int32 width = Engine.GraphicsManager.PreferredBackBufferWidth;
			Int32 height = Engine.GraphicsManager.PreferredBackBufferHeight;

			gameSize = data.GameSize;
			gameBoard = new GameBoard(gameSize, width, height);

			SnakeData[] snakeData = data.SnakeData;
			spriteManager.LoadData(snakeData, gameSize, width, height);
		}

		public void Reset()
		{
			spriteManager.Reset();
		}

		// Update each game object.
		public void Update(GameTime gameTime)
		{
			spriteManager.Update(gameTime);
		}

		// Draw each game object.
		public void Draw()
		{
			gameBoard.Draw();
			spriteManager.Draw();
		}

	}
}